package zb.WX.action.account;

import zb.WX.service.account.QrcodeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "qrcode", urlPatterns = {"/qrcode.jpeg"})
public class QrcodeAction extends HttpServlet {
    /*
     * 获取二维码图片
     * 获取到的图片非常小，通常我们都会将ticket返回页面，通过换取的url地址去获取二维码图片
     * https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET
     * 将TICKET去掉即可
     * (non-Javadoc)
     * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("image/jpeg");
        String qrcode = new QrcodeService().getQrcode("604800", "QR_SCENE", "1111");
        PrintWriter pw = resp.getWriter();
        pw.print(qrcode);
        pw.close();
    }
}
